package com.gdufe.seckill.controller;

import java.util.Arrays;
import java.util.Map;

import com.gdufe.seckill.dto.SeckillRelationDto;
import com.gdufe.seckill.vo.SeckillProDetailsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gdufe.seckill.entity.RelationEntity;
import com.gdufe.seckill.service.RelationAdminService;
import com.gdufe.common.utils.PageUtils;
import com.gdufe.common.utils.R;


@RestController
@RequestMapping("seckill/relation/admin")
public class RelationAdminController {
    @Autowired
    private RelationAdminService relationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = relationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		RelationEntity relation = relationService.getById(id);

        return R.ok().put("relation", relation);
    }
    //返回秒杀商品详细信息
    @RequestMapping("/sessionDetails/{id}")
    public R sessionDetails(@PathVariable("id") Integer id){
        SeckillProDetailsVo relation = relationService.sessionDetails(id);

        return R.ok().put("relation", relation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody RelationEntity relation){
		relationService.save(relation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody RelationEntity relation){
		relationService.updateById(relation);

        return R.ok();
    }

    /**
     *修改秒杀商品启用状态
     */
    @RequestMapping("/status")
    public R updateStatus(@RequestBody SeckillRelationDto dto){

        relationService.updateStstus(dto);
        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		relationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
